import json
class CAddress:
    def __init__(self,host="",port=8080,addrType = 1):
        self.__host = host
        self.__port = port
        self.__addrType = addrType
    
    @property
    def host(self):
        return self.__host

    @host.setter
    def host(self,value):
        self.__host=value

    @property
    def port(self):
        return self.__port

    @port.setter
    def port(self,value):
        self.__port =value
    
    @property
    def addrType(self):
        return self.__addrType

    @addrType.setter
    def addrType(self,value):
        self.__addrType =value


   #Object——>jsonStr
    def serializeToJsonStr(self):
        sttr=json.dumps(self, default=lambda obj: obj.__dict__)
        return sttr.replace("_CAddress__","")

    #jsonStr——> Object
    @classmethod
    def deserializeFromJsonStr(cls,jsonStrobjectdata):
        d = json.loads(jsonStrobjectdata)
        #print(d['txins'])
        return  cls(d['host'],d['port'],d['addrType'])
       
    #Object——>Python Object
    def serializeToPyObject(self):
        return json.loads(self.serializeToJsonStr())
    
    #Python Object——>Object
    @classmethod
    def deserializeFromPyObject(cls,pyObject):
       return cls.deserializeFromJsonStr(json.dumps(pyObject))